package com.maszy.filter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.maszy.bean.StaffLogin;




public class CheckLogin implements Filter {


	public void doFilter(ServletRequest request, ServletResponse response,

	FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)request;
		HttpServletResponse res=(HttpServletResponse)response;
	
		StaffLogin obj = new StaffLogin();
		try{
			obj=(StaffLogin) req.getSession().getAttribute("m");
			
		}catch(Exception e){
			e.printStackTrace();
		}		
		if(obj==null){
			request.setAttribute("error", "您尚未登陆，请先登陆");
			res.sendRedirect(req.getContextPath()+"/web/admin/error.jsp");
		}else{
			chain.doFilter(request, response);
		}
		

	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}




}
